
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>产品列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            color: #333;
            padding: 20px;
        }
        h1 {
            color: #007bff;
            text-align: center;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        th, td {
            padding: 12px;
            text-align: center;
            border: 1px solid #ccc;
        }
        th {
            background-color: #007bff;
            color: white;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        tr:hover {
            background-color: #e2e6ea;
        }
        form {
            display: inline;
        }
        input[type="number"] {
            width: 60px;
            padding: 5px;
            border-radius: 3px;
            border: 1px solid #ccc;
            margin-right: 5px;
        }
        input[type="submit"] {
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            padding: 6px 12px;
            transition: background-color 0.3s;
        }
        input[type="submit"]:hover {
            background-color: #218838;
        }
        a {
            display: block;
            text-align: center;
            margin-top: 20px;
            text-decoration: none;
            color: #007bff;
        }
        a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
<h1>商品选购</h1>
<c:if test="${empty products}">
    <p style="text-align: center;">没有找到产品信息。</p>
</c:if>
<table>
    <tr>
        <th>产品名称</th>
        <th>产品价格</th>
        <th>剩余库存</th>
        <th>操作</th>
    </tr>
    <c:forEach var="product" items="${products}">
        <tr>
            <td>${product.name}</td>
            <td>${product.price}</td>
            <td>${product.stock}</td>
            <td>
                <form action="cart" method="get">
                    <input type="hidden" name="action" value="add">
                    <input type="hidden" name="id" value="${product.id}">
                    <input type="number" name="stock" value="1" min="1" max="${product.stock}"/>
                    <input type="submit" value="添加到购物车">
                </form>
            </td>
        </tr>
    </c:forEach>
</table>
<a href="cart.jsp">查看购物车</a>
</body>
</html>